package org.RSG.Interface;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;

import org.RSG.Application.*;

public class NewDialog implements ActionListener
{
	public JInternalFrame window;
	private JSpinner width_spnr;
	private JSpinner height_spnr;
	public NewDialog()
	{
		this.window = new JInternalFrame("New", false, false, false, false);
		this.window.setPreferredSize(new Dimension(400, 300));
		Container content = this.window.getContentPane();
		content.setLayout(new GridBagLayout());

		this.window.add(new JLabel("Width: "));
		SpinnerModel wmodel = new SpinnerNumberModel(16, 1, 128, 1);
		this.width_spnr = new JSpinner(wmodel);
		this.window.add(width_spnr);
		
		this.window.add(new JLabel("Height: "));
		SpinnerModel hmodel = new SpinnerNumberModel(16, 1, 128, 1);
		this.height_spnr = new JSpinner(hmodel);
		this.window.add(height_spnr);
		JButton create_btn = new JButton("Create Image");
		create_btn.addActionListener(this);
		this.window.add(create_btn);
		
		this.window.pack();
		this.window.setLocation(new Point((Application.appdesktop.desktop.getWidth() / 2) - (this.window.getWidth() / 2), (Application.appdesktop.desktop.getHeight() / 2) - (this.window.getHeight() / 2)));
		this.window.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		ImageWindow tmp = new ImageWindow(Integer.parseInt(this.width_spnr.getValue().toString())*10, Integer.parseInt(this.height_spnr.getValue().toString())*10, "Untitled Image " + Application.IMGN);
		Application.appdesktop.desktop.add(tmp.window);
		try {
			tmp.window.setSelected(true);
		} catch (PropertyVetoException e1) {
			e1.printStackTrace();
		}
		this.window.setVisible(false);
	}
}